import React, { useState, useEffect } from 'react'
import Head from 'next/head'
import { Row, Col, List } from 'antd'
import ArticleBd from '../components/ArticleBd'
import MyList from '../components/MyList'
import Header from '../components/Header'
import Author from '../components/Author'
import Advert from '../components/Advert'
import Footer from '../components/Footer'
import '../static/style/pages/list.less'
import servicePath from '../config/apiUrl'
import { getUrlToken } from '../utils/handler'
const that = React;



const PageList = (props) => {


    const [mylist, setMylist] = useState(props.data);

    useEffect(() => {
        setMylist(props.data)
    }, props.data)

    console.log("pageList==", props)
    return (
        <div>
            <Head>
                <title>list</title>
            </Head>
            <Header />
            <Row className="comm-main" type="flex" justify="center">
                <Col className="comm-left" xs={24} sm={24} md={16} lg={18} xl={14}  >
                    <div>
                        <ArticleBd  breadCustomName={props.data[0]['typeName']}/>

                        <MyList itemLayout="vertical" bordered dataSource={mylist} />

                    </div>
                </Col>

                <Col className="comm-right" xs={0} sm={0} md={7} lg={5} xl={4}>
                    <Author />
                    <Advert />
                </Col>
            </Row>
            <Footer />

        </div>
    )

}



PageList.getInitialProps = async (ctx) => {
    console.log("list-框架页面--ctx", ctx)
    let id = ctx.query.id;
    const result = new Promise((resolve) => {
        that.$http(`${servicePath.getListById}${id}`).then(res => {
            resolve(res.data)
        })
    })
    return await result
}

export default PageList